package com.springboot.config;

import com.springboot.interceptor.UerInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration  //定义此类为配置文件（相当于之前的xml配置文件）
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //要拦截user下的所有访问请求，必须用户登录后才能访问，
        //但是拦截路径有些是不需要登录也能访问的
        String[] addPathPatterns={
            "/user/**"
        };
        //排除的路径说明用户不登陆也能访问
        String[] excludePathPatterns={
            "/user/out","/user/error","/user/login"
        };
        registry.addInterceptor(new UerInterceptor()).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);
    }
}
